package java6681.newdate;

import javafx.fxml.FXML;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.MonthDay;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.Scanner;

/**
 * @author Junichiro
 * @description BirthDay6681Controller 自写有bug
 * @date 2021-03-23 12:59
 **/

/*
 * BirthDay6681Controller 自写有bug
 * */
public class Test {

        @FXML
        private DatePicker dpBirthDay;

        @FXML
        private Label lblResult;

        @FXML
        void change() {
            /*清空DataPicker文本框中的所有内容*/
            if (dpBirthDay.getValue() == null) {
                lblResult.setText(" ");
            }
            LocalDate now = LocalDate.now();
            /*设置规则*/
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-M-dd");
            /*获取日期*/
            LocalDate value = dpBirthDay.getValue();
            /*日期转为String类型*/
            String format = value.format(dtf);
            MonthDay day = MonthDay.parse(format, dtf);
            /*与现在的时间对比,计算还有几天生日*/
            int result = day.compareTo(MonthDay.now());
//        long until1 = value.until(now, ChronoUnit.DAYS);
            /*计算几岁*/
            long until = value.until(now, ChronoUnit.YEARS);
            if (result == 0) {
                lblResult.setText("生日快乐");
            } else if (result > 0) {
                lblResult.setText("还有" + Math.abs(result) + "天," + until + "岁生日" + "有惊喜");
            } else {
                lblResult.setText("等待来年！");
            }
        }
    }

